package com.yipinhouse.reception.app.apiImpl;

import com.yipinhouse.common.result.Result;

import com.yipinhouse.reception.client.SigningWebQueryClient;
import com.yipinhouse.reception.common.utils.JwtUtil;
import com.yipinhouse.signing.client.ContractQueryClient;
import com.yipinhouse.signing.client.SigningQueryClient;
import com.yipinhouse.signing.client.result.ContractResult;
import com.yipinhouse.signing.client.result.HouseTradeResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("reception")
public class SigningApiImpl implements SigningWebQueryClient {

    @Resource
    private SigningQueryClient signingQueryClient;

    @Resource
    private ContractQueryClient contractQueryClient;

    @Override
    public Result<List<HouseTradeResult>> getHouseTradeByUser() {
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = requestAttributes.getRequest();
        String userId1 = request.getHeader("userId");
        Integer userId = Integer.valueOf(userId1);
        Result<List<HouseTradeResult>> houseTradeByUser = signingQueryClient.getHouseTradeByUser(userId);
        return houseTradeByUser;
    }

    @Override
    public Result<HouseTradeResult> getHouseTradeById(Integer houseTradeId) {
        Result<HouseTradeResult> houseTradeById = signingQueryClient.getHouseTradeById(houseTradeId);
        return houseTradeById;
    }

    @Override
    public Result<List<ContractResult>> getContractByUser() {
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = requestAttributes.getRequest();
        String userId1 = request.getHeader("userId");
        Integer userId = Integer.valueOf(userId1);
        Result<List<ContractResult>> contractByUser = contractQueryClient.getContractByUser(userId);
        return contractByUser;
    }
}
